<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="framelib.common.FrameCommon"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@include file="includes/import.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="<%=basePathHeader%>/JAVAScripts/common/date.js"></script>
<script type="text/javascript" src="<%=basePathHeader%>/JAVAScripts/common/formValidator-4.1.1.js"></script>
<script type="text/javascript" src="<%=basePathHeader%>/JAVAScripts/common/formValidatorRegex.js"></script>
<link rel="stylesheet" href="<%=basePathHeader%>/styles/userInfo.css"
			type="text/css" />
<script type="text/javascript" language="javascript">
$(document).ready(function(){
	$.formValidator.initConfig({theme:"126",submitOnce:true,formID:"userInfo",
		onError:function(msg){},
		submitAfterAjaxPrompt : '有数据正在异步验证，请稍等...'
	});
	$("#nickname").formValidator({onShowFixText:"6~12个字符，包括字母、数字、下划线，以字母开头，字母或数字结尾",onShowText:"请输入昵称",onShow:"",onCorrect:"该昵称可以注册"}).inputValidator({min:6,max:12,onError:"你输入的昵称长度不正确,请确认"}).regexValidator({regExp:"username",dataType:"enum",onError:"昵称格式不正确"})
	    .ajaxValidator({
		dataType : "json",
		async : true,
		url : "<%=basePathHeader %>/checkUser.htm",
		success : function(data){
			return true;
		},
		buttons: $("#button"),
		error: function(jqXHR, textStatus, errorThrown){return false;},
		onError : "该昵称不可用，请更换昵称",
		onWait : "正在进行合法性校验，请稍候..."
	});
	$("#county").formValidator({onShow:"请选择所在区",onFocus:"所在区必须选择",onCorrect:"",defaultValue:""}).inputValidator({min:1,onError: "请选择所在区"}).defaultPassed();
	$("#YYYY").formValidator({onShow:"请选择您出生年份",onFocus:"您出生年份必须选择",onCorrect:"",defaultValue:""}).inputValidator({min:1,onError: "请选择您出生年份"}).defaultPassed();
	$("#MM").formValidator({onShow:"请选择您出生月份",onFocus:"您出生月份必须选择",onCorrect:"",defaultValue:""}).inputValidator({min:1,onError: "请选择您出生月份"}).defaultPassed();
	$("#DD").formValidator({onShow:"请选择出生日期",onFocus:"出生日期必须选择",onCorrect:"",defaultValue:""}).inputValidator({min:1,onError: "请选择出生日期"}).defaultPassed();
	$("#email").val('<c:out value='${sessionScope.pnnSession.email}'/>');
	$("#nickname").val('<c:out value='${sessionScope.pnnSession.nickName}'/>');
	$("#county").attr("value","<c:out value='${sessionScope.pnnSession.userParams[3].extValue}'/>");
	$("#YYYY").attr("value","<c:out value='${fn:split(sessionScope.pnnSession.userParams[4].extValue, "-")[0]}'/>");
	$("#MM").attr("value","<c:out value='${fn:split(sessionScope.pnnSession.userParams[4].extValue, "-")[1]}'/>");
	$("#DD").attr("value","<c:out value='${fn:split(sessionScope.pnnSession.userParams[4].extValue, "-")[2]}'/>");
	//$("input[type=radio]").attr("checked",'<c:out value='${sessionScope.pnnSession.userParams[0].extValue}'/>');
	//$("input[@name=sex][@value={$'男'}]").attr("checked",true);
	$("#sex").click().val('男');
	
	// 使用 jQuery 异步提交表单
	$('#userInfo').submit(function() {
		jQuery.ajax({
			url: '<%=basePathHeader %>/user/updateUserInfo.htm',
			data: $('#userId').serialize()+'&' + $('#email').serialize()+'&' + $('#nickname').serialize()+'&' + 'sex='+$('input[name="sex"]').filter(':checked').val()+'&' + $('#province').serialize()+'&' + $('#city').serialize()+'&' + $('#county').serialize()+'&' + $('#YYYY').serialize()+'&' + $('#MM').serialize()+'&' + $('#DD').serialize(),
			type: "POST",
            complete :function(){},
			success: function(data){
				if(data == 'success'){
					window.location = "<%=basePathHeader %>/initIndex.htm";
				}else{
					var message = '';
					if(data == 'error'){
						message = '';
					}
					$('#error').html(message);
				}
			}
		});
		return false;
	});
});

function userInfoSubmit(){
	$('#userInfo').submit();
}
</script>

</head>

<body>
<c:import url="includes/header.jsp" />
<div class="info">
	<c:import url="includes/userLeft.jsp" />
	<div class="right">
		<form id="userInfo" action="<%=basePathHeader %>/user/updateUserInfo.htm" method="post">
		<input type="hidden" id="userId" name="userId" value="<c:out value='${sessionScope.pnnSession.id}'/>"/>
		<input type="hidden" id="email" name="email" value="<c:out value='${sessionScope.pnnSession.email}'/>"/>
		<input type="hidden" id="county-permission" name="county-permission" value="<c:out value='${sessionScope.pnnSession.userParams[3].permission}'/>"/>
		<input type="hidden" id="birthday-permission" name="birthday-permission" value="<c:out value='${sessionScope.pnnSession.userParams[4].permission}'/>"/>
		  
		  
		  
		  <div class="reg_user">
				       <label>邮箱地址：</label>
				 			 <div class="reg_useright">
							 <span id="emailTip" class="reg_note col_999 email"><c:out value="${sessionScope.pnnSession.email}"/></span>
							 </div>
							 <div class="clear"></div>
							 </div>
				       <div class="reg_user">
				       <label>昵称：</label>
							 <div class="reg_useright">
				 			 <input type="text" id="nickname" name="nickname" class="g-ipt"/>  
				 			 <span id="nicknameTip" class="reg_note col_999"></span><br />
				 			 <p class="reg_note col_999">密码长度只能在6-12个字符</p>
							 </div>
							 <div class="clear"></div>
							 </div>
							 
				       <div class="reg_user">
				       <label>性别：</label>
							 <div class="reg_useright">
							 <input name="sex" type="radio" value="男" checked="checked"><span>男</span></input><input name="sex" type="radio" value="女"><span>女</span></input><br />
							 <span id="sexTip" class="reg_note col_999"></span>
							 </div>
							 <div class="clear"></div>
							 </div>
							 
				       <div class="reg_user">
				       <label>所在地：</label>
							 <div class="reg_useright">
							 <input type="hidden" id="province" name="province" value="北京市"/>
							<input type="hidden" id="city" name="city" value="北京市"/>
							<select name="city1" disabled="disabled">
								<option value="北京市">北京市</option>
							</select>
							 &nbsp;
							 <select id="county" name="county" style="width: 120px;">
							 	<option value="东城区">东城区</option>
							 	<option value="西城区">西城区</option>
							 	<option value="崇文区">崇文区</option>
							 	<option value="宣武区">宣武区</option>
							 	<option value="朝阳区">朝阳区</option>
							 	<option value="丰台区">丰台区</option>
							 	<option value="石景山区">石景山区</option>
							 	<option value="海淀区">海淀区</option>
							 	<option value="门头沟区">门头沟区</option>
							 	<option value="房山区">房山区</option>
							 	<option value="通州区">通州区</option>
							 	<option value="顺义区">顺义区</option>
							 	<option value="昌平区">昌平区</option>
							 	<option value="大兴区">大兴区</option>
							 	<option value="怀柔区">怀柔区</option>
							 	<option value="平谷区">平谷区</option>
							 	<option value="密云县">密云县</option>
							 	<option value="延庆县">延庆县</option>
							 	<option value="延庆镇">延庆镇</option>
							</select>
							 <span id="countyTip" class="reg_note col_999"></span>
							 </div> 
							 <div class="clear"></div>
							 </div>
							 
				       <div class="reg_user">
				       		<label>生日：</label>
							<div class="reg_useright">
								<select id="YYYY" name="YYYY"></select> 年
								<select id="MM" name="MM"></select> 月
								<select id="DD" name="DD"></select> 日
								<span id="YYYYTip" class="reg_note col_999"></span>
								<span id="MMTip" class="reg_note col_999"></span>
								<span id="DDTip" class="reg_note col_999"></span>
							</div> 
							<div class="clear"></div>
					   </div>
							 <span class="reg_infobtn" onclick="userInfoSubmit()"></span>
							 
							 
							 
		</form>
	</div>
</div>

<c:import url="includes/footer.jsp" />
</body>
</html>
